# Copyright 2024-2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_library.bzl", "cc_library")

package(
    default_visibility = ["//visibility:private"],
)

cc_binary(
    name = "libink.so",
    additional_linker_inputs = ["jni.lds"],
    features = ["-legacy_whole_archive"],
    linkopts = [
        # Use a linker script to limit exported symbols to JNI functions.
        "-Wl,--version-script=$(location :jni.lds)",
    ],
    linkshared = 1,
    linkstatic = 1,
    deps = [
        ":jni.lds",
        ":jni_onload",
        "//ink/color/internal/jni:native",
        "//ink/geometry/internal/jni:native",
        "//ink/jni/internal:jni_defines",
        "//ink/jni/internal:jni_jvm_interface",
        "//ink/rendering/skia/common_internal/jni:native",
        "//ink/storage/internal/jni:native",
        "//ink/strokes/internal/jni:native",
    ],
)

cc_library(
    name = "jni_onload",
    srcs = ["jni_onload.cc"],
    deps = [
        "//ink/jni/internal:jni_jvm_interface",
        "@com_google_absl//absl/log:absl_check",
    ] + select({
        "@platforms//os:android": [],
        "//conditions:default": [
            "@rules_jni//jni",
        ],
    }),
)
